<div class="table-search">
    <form class="form-horizontal clearfix">
        <div class="form-body">
            <div class="form-group" style="padding-bottom: 15px;border-bottom: 1px solid #eee">
                <label class="control-label col-xs-1" style="width: 100px">签约时间</label>
                <div class="col-xs-6">
                    <select class="input-sm" style="width: 110px" name="province">
                        <option>最近90天</option>
                        <option>最近30天</option>
                        <option>最近一年</option>
                    </select>
                    <span class="input-icon input-icon-right" style="width: 224px">
                        <input type="text" value="<?= $timeRange?>" class="form-control input-sm" name="total_fee_min"/>
                        <i class="ace-icon fa fa-calendar"></i>
                    </span>
                </div>
            </div>
        </div>
        <div class="form-footer col-xs-2" style="float: right;text-align: right">
            <button class="btn btn-primary btn-xs" style="margin-right: 5px" type="button" onclick="refreshTable()"><i class="fa fa-search"></i> 搜索</button>
            <button class="btn btn-light btn-xs"><i class="fa fa-undo"></i> 重置</button>
        </div>
    </form>
</div>
<div class="table-tools clearfix" id="toolbar">
    <div data-toggle="buttons" class="btn-group btn-overlap btn-corner" style="float: left;margin-right: 30px">
        <label class="btn btn-white" style="width: 100px"><input type="radio" value="1" /> 全部</label>
        <label class="btn btn-white active" style="width: 100px"><input type="radio" value="2" /> 进行中</label>
        <label class="btn btn-white" style="width: 100px"><input type="radio" value="3" /> 待审核</label>
        <label class="btn btn-white" style="width: 100px"><input type="radio" value="3" /> 已驳回</label>
        <label class="btn btn-white" style="width: 100px"><input type="radio" value="3" /> 已完成</label>
    </div>
    <div style="float: left" class="table-tools-btn">
        <a class="btn btn-primary" href="add"><i class="ace-icon fa fa-plus"></i>录入合同</a>
    </div>
</div>
    <table id="list-container"></table>
<?php $this->beginBlock('js') ?>
<script type="text/javascript">
    var urls = {
        index: 'index',
        disable: 'disable',
        enable: 'enable',
        add: 'add',
        edit: 'edit',
        products: 'products',
    }
    var tableContainer = $('#list-container')
    var tableSearchForm = '.table-search form'
    initTable()
    function refreshTable() {
        tableContainer.bootstrapTable('refresh', {
            query: ace.form.serialize(tableSearchForm)
        })
    }
    function initTable () {
        tableContainer.bootstrapTable('destroy');
        var columns = [
            {title: '合同编号', field: 'code'},
            {title: '采购方', field: 'level_msg'},
            {title: '地区', field: 'pcc'},
            {title: '金额（万元）', field: 'total_fee'},
            {title: '签约时间', field: 'sign_at'},
            {title: '周期（月）', field: 'month'},
            {title: '总量（箱）', field: 'amount'},
            {title: '已发货数量（箱）', field: 'amount'},
            {title: '状态', field: 'status', formatter: function(value, row, index){
                if (value == 1)
                    return '<span class="badge badge-primary">待审核</span>'
                else if (value == 2)
                    return '<span class="badge badge-danger">驳回</span>'
                else if (value == 3)
                    return '<span class="badge badge-info">审核通过，进行中</span>'
                else if (value == 4)
                    return '<span class="badge badge-success">已完结</span>'
            }},
            {title: '最后修改时间', field: 'updated_at'},
            {title: '操作', cellStyle: {
                    css: {'max-width': '240px'},
                },class: 'actions', formatter: function(value, row, index) {
                    var html = '';
                    if (row.status==1) {
                        html += '<a action="disable" url="'+urls.disable+'">禁用</a>'
                    } else {
                        html += '<a action="enable" url="'+urls.enable+'">启用</a>'
                    }
                    html += '<a class="save-item" url="'+urls.edit+'">编辑</a>';
                    html += '<a action="remove" url="'+urls.remove+'">删除</a>';
                    html += '<div class="inline more-actions"><div class="dropdown">'+
                        '<button class="btn dropdown-toggle" data-toggle="dropdown">更多操作<span class="caret"></span></button>'+
                        '<ul class="dropdown-menu pull-right" style="min-width: 80px">'+
                        '<li><a href="'+urls.deliverys+'" target="_blank">发货管理</a></li>'+
                        '<li><a href="'+urls.products+'" target="_blank">配套物资</a></li>'+
                        '<li><a onclick="showAttachments('+row.id+')" target="_blank">合同附件</a></li>'+
                        '<li><a onclick="showLogs('+row.id+')">操作日志</a></li>'+
                        '</ul>'+
                        '</div></div>'
                    return html;
                }}
        ]
        tableContainer.bootstrapTable({
            url: urls.index,
            uniqueId: "id",
            striped: true,
            toolbar: '#toolbar',
            search: true,
            showColumns: true,
            pagination: true,
            sidePagination: "server",
            pageSize: 20,
            pageList: [10, 20, 50, 100],
            columns: columns,
            queryParams: function (params) {
                return $.extend({}, params, ace.form.serialize(tableSearchForm))
            }
        });
    }
</script>
<?php $this->endBlock() ?>
